//
//  UIGLESSettingViewController.m
//  TextureText
//
//  Created by 畑圭輔 on 10/03/07.
//  Copyright 2010 Keisuke Hata. All rights reserved.
//

#import "UIGLESSettingViewController.h"

extern NSString * const kImageKeyCharactor2;

@implementation UIGLESSettingViewController

@synthesize glView;

- (IBAction) show {
	
	ControlView *view = (ControlView *)self.view;
	
	if( !_isOpened )
	{	
		[view open];
		_isOpened = YES;
		
	}else {
		[view close];
		_isOpened = NO;
		
	}
	NSLog(@"show view");
}

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

// フォント一覧を作成して格納する
- (void) createFontNames {
	
	NSArray *families = [[NSArray alloc] initWithArray:[UIFont familyNames]];
	if( _fontTypes != nil )
		[_fontTypes release];
	
	_fontTypes = [[NSMutableArray alloc] init];
	for (int i = 0; i < [families count]; i++) 
	{
		[_fontTypes addObject:[families objectAtIndex:i]];
	}
	[families release];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	
	_isOpened = NO;
	_fontTypes = nil;
	
	NSLog(@"viewLoad!!");
	CGRect frame = self.view.frame;
	frame.origin.y = self.view.frame.size.height - 40;
	_fontTypePicker.frame = CGRectMake(_fontTypePicker.frame.origin.x, 
										_fontTypePicker.frame.origin.y + 20, 
										_fontTypePicker.frame.size.width, 
										_fontTypePicker.frame.size.height);

	// フォント一覧を作成
	[self createFontNames];
	
	[self.view setFrame:frame];
    [super viewDidLoad];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

#pragma mark -
#pragma mark UIPickerViewDataSource

// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
	
	return 1;/* １列 */
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
	
	return [_fontTypes count];
}

#pragma mark -
#pragma mark UIPickerViewDelegate

/*
 - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
 
 }
 */

/*
 - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
 }
 */

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
	
	return [_fontTypes objectAtIndex:row];
}

/*
 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
 
 }
 */

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
	
	// テキストテクスチャを更新
	[glView updateTextureText:[_fontTypes objectAtIndex:row]];
}

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}

- (void)dealloc {
	[_fontTypes release];
    [super dealloc];
}


@end
